/*     */ package com.cr.common.json;
/*     */ 
/*     */ import com.fasterxml.jackson.core.JsonGenerationException;
/*     */ import com.fasterxml.jackson.core.JsonParseException;
/*     */ import com.fasterxml.jackson.databind.JsonMappingException;
/*     */ import com.fasterxml.jackson.databind.ObjectMapper;
/*     */ import com.fasterxml.jackson.databind.ObjectWriter;
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.OutputStream;
/*     */ 
/*     */ public class JSON {
/*     */   public static final String DEFAULT_FAIL = "\"Parse failed\"";
/*     */   
/*  21 */   private static final ObjectMapper objectMapper = new ObjectMapper();
/*     */   
/*  22 */   private static final ObjectWriter objectWriter = objectMapper.writerWithDefaultPrettyPrinter();
/*     */   
/*     */   public static void marshal(File file, Object value) throws Exception {
/*     */     try {
/*  28 */       objectWriter.writeValue(file, value);
/*  30 */     } catch (JsonGenerationException e) {
/*  32 */       throw new Exception(e);
/*  34 */     } catch (JsonMappingException e) {
/*  36 */       throw new Exception(e);
/*  38 */     } catch (IOException e) {
/*  40 */       throw new Exception(e);
/*     */     } 
/*     */   }
/*     */   
/*     */   public static void marshal(OutputStream os, Object value) throws Exception {
/*     */     try {
/*  48 */       objectWriter.writeValue(os, value);
/*  50 */     } catch (JsonGenerationException e) {
/*  52 */       throw new Exception(e);
/*  54 */     } catch (JsonMappingException e) {
/*  56 */       throw new Exception(e);
/*  58 */     } catch (IOException e) {
/*  60 */       throw new Exception(e);
/*     */     } 
/*     */   }
/*     */   
/*     */   public static String marshal(Object value) throws Exception {
/*     */     try {
/*  68 */       return objectWriter.writeValueAsString(value);
/*  70 */     } catch (JsonGenerationException e) {
/*  72 */       throw new Exception(e);
/*  74 */     } catch (JsonMappingException e) {
/*  76 */       throw new Exception(e);
/*  78 */     } catch (IOException e) {
/*  80 */       throw new Exception(e);
/*     */     } 
/*     */   }
/*     */   
/*     */   public static byte[] marshalBytes(Object value) throws Exception {
/*     */     try {
/*  88 */       return objectWriter.writeValueAsBytes(value);
/*  90 */     } catch (JsonGenerationException e) {
/*  92 */       throw new Exception(e);
/*  94 */     } catch (JsonMappingException e) {
/*  96 */       throw new Exception(e);
/*  98 */     } catch (IOException e) {
/* 100 */       throw new Exception(e);
/*     */     } 
/*     */   }
/*     */   
/*     */   public static <T> T unmarshal(File file, Class<T> valueType) throws Exception {
/*     */     try {
/* 108 */       return (T)objectMapper.readValue(file, valueType);
/* 110 */     } catch (JsonParseException e) {
/* 112 */       throw new Exception(e);
/* 114 */     } catch (JsonMappingException e) {
/* 116 */       throw new Exception(e);
/* 118 */     } catch (IOException e) {
/* 120 */       throw new Exception(e);
/*     */     } 
/*     */   }
/*     */   
/*     */   public static <T> T unmarshal(InputStream is, Class<T> valueType) throws Exception {
/*     */     try {
/* 128 */       return (T)objectMapper.readValue(is, valueType);
/* 130 */     } catch (JsonParseException e) {
/* 132 */       throw new Exception(e);
/* 134 */     } catch (JsonMappingException e) {
/* 136 */       throw new Exception(e);
/* 138 */     } catch (IOException e) {
/* 140 */       throw new Exception(e);
/*     */     } 
/*     */   }
/*     */   
/*     */   public static <T> T unmarshal(String str, Class<T> valueType) throws Exception {
/*     */     try {
/* 148 */       return (T)objectMapper.readValue(str, valueType);
/* 150 */     } catch (JsonParseException e) {
/* 152 */       throw new Exception(e);
/* 154 */     } catch (JsonMappingException e) {
/* 156 */       throw new Exception(e);
/* 158 */     } catch (IOException e) {
/* 160 */       throw new Exception(e);
/*     */     } 
/*     */   }
/*     */   
/*     */   public static <T> T unmarshal(byte[] bytes, Class<T> valueType) throws Exception {
/*     */     try {
/* 168 */       if (bytes == null)
/* 170 */         bytes = new byte[0]; 
/* 172 */       return (T)objectMapper.readValue(bytes, 0, bytes.length, valueType);
/* 174 */     } catch (JsonParseException e) {
/* 176 */       throw new Exception(e);
/* 178 */     } catch (JsonMappingException e) {
/* 180 */       throw new Exception(e);
/* 182 */     } catch (IOException e) {
/* 184 */       throw new Exception(e);
/*     */     } 
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-common-4.7.0.jar!\com\cr\common\json\JSON.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */